package com.lebang.service;

import com.lebang.common.util.RequestUtil;
import com.lebang.component.UMengPushComponent;
import com.lebang.entity.RequestHeaders;
import com.lebang.entity.member.LbbMemberNotice;
import com.lebang.entity.member.LbbMemberRecord;
import com.lebang.mapper.LbbMemberNoticeMapper;
import com.lebang.model.enums.Booleans;
import com.lebang.model.enums.NoticeType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Author: hwq
 * @Date: 2019/11/8 15:57
 * @Version 1.0
 */
@Service
public class MemberNoticeService {
    @Autowired
    private LbbMemberNoticeMapper memberNoticeMapper;
    @Autowired
    private UMengPushComponent uMengPushComponent;

    public void addNotice(String title, String text, String memberId, RequestHeaders requsetHeader) {
        LbbMemberNotice memberNotice = new LbbMemberNotice();
        memberNotice.setCreateTime(new Date());
        memberNotice.setModifyTime(new Date());
        memberNotice.setHasDeleted(Booleans.False.name());
        memberNotice.setMemberId(memberId);
        memberNotice.setAppId("xianyu");
        memberNotice.setAppStore(requsetHeader.getAppStore());
        memberNotice.setCategory(NoticeType.Text);
        memberNotice.setTitle(title);
        memberNotice.setSubtitle(text);
        memberNotice.setStatus("On");
        memberNotice.setContent(text);
        memberNoticeMapper.insertSelective(memberNotice);
    }
    @Async
    public void addNoticeAndPush(String title, String text, String memberId, RequestHeaders requsetHeader) {
        this.addNotice(title, text, memberId, requsetHeader);
        uMengPushComponent.sendNoRead(title, text, memberId);
    }

    public void notice(LbbMemberRecord record, String title, String desc){
        String appDesc = "任务通知";
        uMengPushComponent.sendAndroidCustomizedcast(appDesc, desc, record.getMemberId());
        RequestHeaders requestHeaders= RequestUtil.getHeader(record);
        this.addNotice(title, desc, record.getMemberId(), requestHeaders);

    }
}
